package com.jtjrenren.android.taxi.driver.core.user.login;

import android.content.Context;
import android.widget.Toast;

import com.jtjrenren.android.taxi.driver.Constants;

import com.jtjrenren.android.taxi.driver.base.MvpActivity;
import com.jtjrenren.android.taxi.driver.utils.IntentUtils;
import com.jtjrenren.android.taxi.driver.R;
import com.library.weiget.ClearEditText;
import com.library.utils.SpUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/4/27.
 */
public class UserLoginActivity extends MvpActivity<LoginPresenter> implements LoginView {
    @BindView(R.id.login_input_phone)
    ClearEditText et_phone;
    @BindView(R.id.login_input_pwd)
    ClearEditText et_pwd;

    @Override
    public int getLayoutID() {
        return R.layout.aty_user_login;
    }

    @Override
    public void initM() {
        presenter.init();
        et_phone.setText((String) SpUtils.getParam(this, Constants.SP_DRIVER_LASTLOGIN, ""));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.destory();
    }

    @Override
    public LoginPresenterImpl createPresenter() {
        return new LoginPresenterImpl(this);
    }

    @OnClick(R.id.login_forgetpwd)
    void clickForgetPwd() {
        IntentUtils.goForgetPwdActivity(this, true);
    }

    @OnClick(R.id.login_login)
    void clickLogin() {
        presenter.login(et_phone.getText().toString().trim(), et_pwd.getText().toString().trim());
    }

    @OnClick(R.id.login_register)
    void clickRegister() {
        IntentUtils.goRegisterActivity(this, true);
    }

    @Override
    public void showLoadding(String msg) {
        showProDialog(null, msg);
    }

    @Override
    public void hideLoadding() {
        disProDialog();
    }

    @Override
    public void showTip(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    public void loginSuccess() {
        finish();
        IntentUtils.goMainActivity(UserLoginActivity.this);
    }


}
